if (!jsx3.lang.Class.forName("ux.cdb.admin.contract.builder.Builder")) {
/**
 * Define the <code>tibco.spm.design.rule.builder.Builder</code> class.
 * This class inherit from <code>jsx3.gui.Dialog<code> GUI class.
 */
jsx3.Class.defineClass(
		"ux.cdb.admin.contract.builder.Builder",
		jsx3.gui.Dialog,
		null,
		function (objRoot) {

    		/**
			 * This method will be called after UI file has deserialized.
			 */
			objRoot.prototype.onAfterDeserialize = function() {
                this.wizard = this.get("steppedWizard");
                this.service = ux.cdb.admin.contract.ContractPage.Service;
				ux.cdb.admin.CommonCache.loadCache(['AGENT_BANK'], this, function(){
/* @JSC :: begin DEBUG */
					jsx3.log('Customer#Builder#onAfterDeserialize common code cached.');
/* @JSC :: end */
				});				
			};

            objRoot.prototype.closeBuilder = function(noConfirm) {
                if(!noConfirm) this.unLock();
                this.doClose();
            };
            objRoot.prototype.unLock = function(callback) {
                if(this.lockedId){
                    ux.megatron.util.Dwr.callDwr("RetailStudentLoanPreContractUCC", "unlockContract", [this.lockedId], this, function(dwrObject){
                        //console.log(dwrObject);
                        callback;
                    }, "RetailStudentLoanPreContractUCC");
                }
            };
            objRoot.prototype.saveBuilder = function() {
                var result = false, curr, panel, tip, i;
                curr = this.wizard.getCurrentPanel();
                if(this.wizard.editMode == 'New') {
                    for(i=1; i<=4; i++) {
                        panel = this.get("wizPanel_" + i);
                        if(!panel.loaded || !panel.doValidation()) {
                            tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractBuilder@TipUnFinishedStep" + i);
                            this.wizard.getMessageLabel().setText(tip);
                            return;
                        }
                    }
                } else {
                    for(i=2; i<=4; i++) {
                        panel = this.get("wizPanel_" + i);
                        if(panel.loaded && !panel.doValidation()) {
                            tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@contractBuilder@TipUnFinishedStep" + i);
                            this.wizard.getMessageLabel().setText(tip);
                            return;
                        }
                    }
                }

                var _newAppBasicInfo = this.wizard.newAppBasicInfo;

                var _contractPerson = this.wizard.contractPerson;
                var _appBasicInfo = this.wizard.appBasicInfo;  
                var _appIntRateInfo = {}; //TODO: by Eric

                var attrs = ["appAmt","approveStartDate","approveMaturityDate","appCurrencyCode", "feedbackIssueDate",
                    "startDate", "endDate", "appPeriod", "appIntRateTypeCode", "appBenchIntRate", "intRateFloatingRange"];
                for(i=0; i<attrs.length; i++) {
                    //alert(attrs[i] + "=" +_appBasicInfo[attrs[i]]);
                    _newAppBasicInfo[attrs[i]] = _appBasicInfo[attrs[i]];
                }
                _contractPerson.partyId = _newAppBasicInfo.approveInternalOrgId;
                delete _contractPerson.approveInternalOrgName;
                delete _contractPerson.approveInternalOrgId;

                attrs = ["appIntRateTypeCode", "intRateFloatingRange"];
                for(i=0; i<attrs.length; i++) {
                    _appIntRateInfo[attrs[i]] = _appBasicInfo[attrs[i]];
                }
                _appIntRateInfo.appBasicInfoId = _newAppBasicInfo.id.appBasicInfoId;

                //HardCode, Just for test
                _appIntRateInfo.appIntRateId = 1;

                var _acct = this.wizard.accInfo || null;
				
				//console.log('Contract#onSave _newAppBasicInfo:\n' , _newAppBasicInfo);
				this.service.saveContractInfo(_newAppBasicInfo, _contractPerson, _appIntRateInfo, _acct, function(){
                    if(this.opener && this.opener.refreshList) {
                        var opener = this.opener;
                        setTimeout(function() {opener.refreshList();}, 10);
                    }
                    this.closeBuilder(true);
                }, this);
            };
		});
}